package com.zoe.onelink.circuitbreaker.sentinel;

import com.alibaba.cloud.circuitbreaker.sentinel.ReactiveSentinelCircuitBreaker;
import com.alibaba.csp.sentinel.EntryType;
import com.alibaba.csp.sentinel.slots.block.degrade.DegradeRule;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

import java.util.Collections;
import java.util.List;
import java.util.function.Function;

/**
 * <p>标题: </p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2023</p>
 * <p>公司: 智业软件股份有限公司</p>
 *
 * @version: 1.0
 * @author: ruansheng
 * @date: 2023-01-17
 */
public class OnelinkReactiveSentinelCircuitBreaker extends ReactiveSentinelCircuitBreaker {

    private final String resourceName;

    private final EntryType entryType;

    public OnelinkReactiveSentinelCircuitBreaker(String resourceName, EntryType entryType,
                                                 List<DegradeRule> rules) {
        super(resourceName, entryType, rules);
        this.resourceName = resourceName;
        this.entryType = entryType;

    }

    public OnelinkReactiveSentinelCircuitBreaker(String resourceName, List<DegradeRule> rules) {
        this(resourceName, EntryType.OUT, rules);
    }

    public OnelinkReactiveSentinelCircuitBreaker(String resourceName) {
        this(resourceName, EntryType.OUT, Collections.emptyList());
    }

    @Override
    public <T> Mono<T> run(Mono<T> toRun, Function<Throwable, Mono<T>> fallback) {
        return super.run(toRun, fallback);
    }

    @Override
    public <T> Flux<T> run(Flux<T> toRun, Function<Throwable, Flux<T>> fallback) {
        return super.run(toRun, fallback);
    }

}
